package com.ykdl.member.kid.util;

import org.json.JSONException;
import org.json.JSONObject;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;


import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.gears.BaseFragmentActivity;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

import android.app.ProgressDialog;
import android.content.Context;
import android.preference.DialogPreference;

public class ActiveStateUtil {

	private static  ActiveStateUtil instance;
	private ActiveStateUtil(){}
	private static  Context mcontext;
	public   static ActiveStateUtil getInstance(Context context){
		mcontext = context;
		if(instance == null){
			instance = new ActiveStateUtil();
			
		}
		return instance;
	}
	
	public  static void gogoActionsDoctorOnlineByStatus(final String doctor_campaign_id, final ProgressDialog progress){
		
		String url = KidConfig.BASE_TEST_SERVER + "profession/campaigns/"+ doctor_campaign_id +"/status";
		HttpBaseRequest  request = Wxxr.getInstance().getRequest(url, null);
		TaskManager.startHttpRequest(request, new ITag() {
			@Override
			public void refreshUI(Object t, DataState ds) {
				if(null != t && t.toString().contains("status")){
					JSONObject object;
					try {
						progress.dismiss();
						object = new JSONObject(t.toString());
						((BaseFragmentActivity)mcontext).goActionsDoctorOnlineActivity(object.getInt("status"), doctor_campaign_id);
					} catch (JSONException e) {
						progress.dismiss();
					}
					
				}
			}

			@Override
			public boolean refreshError(DataParseError parseError) {
				progress.dismiss();
				return true;
			}
			@Override
			public void refreshCancel() {
				
			}
			
		}, null);
	}
	
}
